/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.app.controller;

import java.io.File;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.app.dto.Filter;
import org.app.model.M_Keyword;
import org.app.utils.EM;
import org.app.utils.PropertiesHelper;
import org.gui.AutoDownloadMovieGUI;

/**
 *
 * @author LamLe
 */
public class Main {

    private static Logger logger = Logger.getLogger(Main.class);

    public static void main(String a[]) {
        new Main().start();
    }

    private void start() {
        // init log4j
        PropertyConfigurator.configure(PropertiesHelper.LOG4J_FILE_PATH);
        try {
            // init properties
            List<String> filters = FileUtils.readLines(new File("properties/filter.properties"));
            for (String s : filters) {
                Filter.add(s);
            }
            EM.em.getTransaction().begin();
            for (int i = 0; i < 15; i++) {
                M_Keyword key = new M_Keyword();
                key.setKeyword("miss march - abc 123");
                EM.em.persist(key);
            }
            EM.em.getTransaction().commit();
            EM.em.close();
            EM.emf.close();
            // init GUI
            AutoDownloadMovieGUI gui = new AutoDownloadMovieGUI();
            gui.setVisible(true);

        } catch (Exception e) {
            logger.error("Failed", e);
        }
    }
}
